<template>
	<view class="content">
		<!-- 授权回调地址：{{url}}, -->
		<view>
			
		
		</view>
	</view>
</template>

<script>
	import app from '@/util/api.js'
	export default {
		data() {
			return {
				url:'',
				code:''
			}
		},
		onLoad() {
			this.sendcode()
			// this.getuserinfo()
		},
		methods: {
			getuserinfo(){
			app.request('api/wechat/auth',{
						  code:this.code,
						
			}).then(res=>{
				app.save('token',res.data.token)
				app.save('userinfo',JSON.stringify(res.data.user))
				let url = app.gets('routerurl')
				if(url == 'index' || url == 'mine/mine'){
					app.snto(url)
				}else{
					app.nto(url)
				}
				// app.confirm('即将前往'+url+'页面，',(res)=>{
					
				// },()=>{	app.nto(url)})
						
			})	
			},
  sendcode() {
        let that = this
      var url = window.location.href;
	  this.url = url
      var uid = app.gets('token')
      // 有userid就不请求了
      if (!uid) {
        if (url.split("code=").length > 1) {
          var code = url.split("=")[1].split("&")[0];
		  that.code = code
		  app.toast(code)
		  that.getuserinfo()
		 
        }else{
			app.toast('code获取失败')
		}
      }else{
		  let url = app.gets('routerurl')
		  app.nto(url)
	  }
    }
		}
	}
</script>

<style scoped>

</style>
